package cheme.ProcessEditor.Parts.Streams;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.draw2d.Cursors;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.ConnectionEditPart;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.tools.SimpleDragTracker;
import org.eclipse.swt.graphics.Cursor;

import cheme.ProcessEditor.Parts.Streams.Tag.PartTag;

public class TagDragTracker extends SimpleDragTracker
{
	PartTag sourceEditPart;
	private ConnectionEditPart editpart;
	
	public TagDragTracker(PartTag sourceEditPart, ConnectionEditPart Connection)
	{
		setConnectionEditPart(Connection);
		this.sourceEditPart = sourceEditPart;
	}
	
	public void setConnectionEditPart(ConnectionEditPart cep)
	{
		editpart = cep;
	}
	
	protected List createOperationSet()
	{
		List list = new ArrayList();
		list.add(getConnectionEditPart());
		return list;
	}
	
	protected ConnectionEditPart getConnectionEditPart()
	{
		return editpart;
	}

	@Override
	protected Cursor getDefaultCursor()
	{
		return Cursors.ARROW;
	}

	@Override
	protected Command getCommand()
	{
		return getConnectionEditPart().getCommand(getSourceRequest());
	}
	
	@Override
	protected String getCommandName()
	{
		return null;
	}
	
	protected Request createSourceRequest()
	{
		MoveTagRequest req = new MoveTagRequest(sourceEditPart);
		req.setFeedbackBounds(new Rectangle(getLocation(), sourceEditPart.getFigure().getPreferredSize()));
		return req;
	}
	
	@Override
	protected void updateSourceRequest()
	{
		MoveTagRequest req = (MoveTagRequest)getSourceRequest();

		req.setStartLocation(getStartLocation());
		req.setLocation(getLocation());
		req.setDelta(getDragMoveDelta());
		
//		System.out.println("---");
//		System.out.println("\tStart Location: " + getStartLocation());
//		System.out.println("\tLocation: " + getLocation());
//		System.out.println("\tDelta: " + getDragMoveDelta());
		
		super.updateSourceRequest();
	}
}
